package cn.net.awit.API.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.web.system.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.net.awit.API.entity.JSONResult;
import cn.net.awit.weaapp.service.WeaAppServiceI;


/**   
 * @Title: Controller  
 * @Description: 移动端更新
 * @author onlineGenerator
 * @date 2018-10-29 09:33:37
 * @version V1.0
 *
 */
@Controller
@RequestMapping("/appUpdate")
//@Api(value = "appUpdate", description = "app更新接口", tags = "appUpdateAPI")
public class AppUpdateController extends BaseController {
	
	@Autowired
	private WeaAppServiceI weaAppService;
	@Autowired
	private SystemService systemService;
	
	/**
	 * restful风格示例
	 * url:http://localhost:8080/GuiYang_weather_BS/rest/appUpdate/test
	 * token通过header中发送，key为X-AUTH-TOKEN
	 * @return
	 */
//	@RequestMapping(value="/appVersion",method = RequestMethod.GET)
//	@ResponseBody
////	@ApiOperation(value = "appVersion",produces="application/json",httpMethod="GET")
//	public JSONResult appVersion(HttpServletRequest request, HttpServletResponse response){
//		JSONResult jsonResult = new JSONResult(1, "sdf");
//		InterfaceRuleDto interfaceRuleDto = InterfaceUtil.getInterfaceRuleDto(request, InterfaceEnum.app_version);
//		if(interfaceRuleDto==null){
//			jsonResult.setCode(0);
//			jsonResult.setMsg("您没有接口权限");
//		}
//		return jsonResult;
//	}
	
	/**
	 * 获取版本信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(params="appVersion",method = RequestMethod.GET)
	@ResponseBody
	public JSONResult appVersion(HttpServletRequest request, HttpServletResponse response){
		JSONResult jsonResult = new JSONResult(1, "获取版本信息成功！！！");
		try {
			String file_panel = request.getParameter("file_panel");
			List<Map<String, Object>> list = 
					weaAppService.findForJdbc("select top 1 version_name,version_code,desctition,add_time,file_name,file_size from wea_app where file_panel = ? order by version_num desc", file_panel);
			jsonResult.addObj("data", list);
		} catch (Exception e) {
			jsonResult.setCode(0);
			jsonResult.setMsg(e.getMessage());
		}
		return jsonResult;
	}
	
}
